class util {
    padDate(va) {
        va = va < 10 ? '0' + va : va;
        return va
    }
    getItem(key) {
        if (window.localStorage) {
            return window.localStorage.getItem(key);
        } else {
            return Cookie.read(key);
        }
    }
    setItem(key,val){
        if (window.localStorage) {
            localStorage.setItem(key,val);
        } else {
            Cookie.write(key,val);
        }
    }
    findIndex(target, data, param){
        let index = -1;
        data.map((item, key) => {
            if(item[param] === target){
                index = key;
                return
            }
        });
        return index
    }
    excludeSpecial (s) {  
        // 去掉转义字符  
        s = s.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');  
        // 去掉特殊字符  
        s = s.replace(/[\@\#\$\%\^\&\*\{\}\:\"\L\<\>\?]/);  
        return s;  
    }
    creatCompare(propertyName) { //根据哪个属性值排序
        return function (obj1,obj2) {
            //对象两两比较
            let value1=obj1[propertyName]-0;
            let value2=obj2[propertyName]-0;
            if(value1<value2){
                return -1
            }else if(value1>value2){
                return 1
            }else {
                return 0
            }
        }
    }
    hasToAttr(arr, atr){
        return arr.map((i)=>{
            return i[atr]
        })
    }

}

export default util
